package com.session; /**
 * @author wzm
 * @create 2023-03-13 14:41
 */

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/session01")
public class SessionServlet01 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //将数据存储到Session
        //1.获取session对象
        HttpSession session = request.getSession();

        //2.存储数据 值可以是字符串  对象  集合
        session.setAttribute("username", "zs");


        //session默认时长30分钟

        //设置超时时间   正数表示设定时长  负数永不超时
        //session.setMaxInactiveInterval(3);//3s以后session

        //让session马上超时
        session.invalidate();



    }
}
